﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class JoyStickInput : IUserInput {

	[Header("===Joystick Setting===")]
	public string axisX = "axisX";
	public string axisY = "axisY";
	public string axis4th = "axis4th";
	public string axis5th = "axis5th";

	public string btn0 = "btn0";
	public string btn1 = "btn1";
	public string btn2 = "btn2";
	public string btn3 = "btn3";
	public string btnLB = "btnLB";
	public string btnRB = "btnRB";
	public string btnJstick = "btn9";

	public MyButton button0 = new MyButton();
	public MyButton button1 = new MyButton();
	public MyButton button2 = new MyButton();
	public MyButton button3 = new MyButton();
	public MyButton buttonLB = new MyButton();
	public MyButton buttonRB = new MyButton();
	public MyButton buttonJstick = new MyButton();

	void Update () {
		
		button0.Tick(Input.GetButton(btn0));
		button1.Tick(Input.GetButton(btn1));
		button2.Tick(Input.GetButton(btn2));
		button3.Tick(Input.GetButton(btn3));
		buttonLB.Tick(Input.GetButton(btnLB));
		buttonRB.Tick(Input.GetButton(btnRB));
		buttonJstick.Tick(Input.GetButton(btnJstick));
		
		Jup = Input.GetAxis(axis5th);
		Jright = Input.GetAxis(axis4th);
		targetDup = Input.GetAxis(axisY) ;
		targetDright = Input.GetAxis(axisX);

		if (inputEnable == false)
		{
			targetDup = 0;
			targetDright = 0;
		}

		Dup = Mathf.SmoothDamp(Dup, targetDup, ref velocityDup, 0.1f);
		Dright = Mathf.SmoothDamp(Dright, targetDright, ref velocityDright, 0.1f);

		Vector2 tempDAxis = SquareToCircle(new Vector2(Dright, Dup));
		float Dright2 = tempDAxis.x;
		float Dup2 = tempDAxis.y;

		Dmag = Mathf.Sqrt((Dup2 * Dup2) + (Dright2 * Dright2));
		Dvec = Dright2 * transform.right + Dup2 * transform.forward;

		run = buttonRB.isPressing;
		defence = buttonLB.isPressing;

		jump = button0.onPressed;
		attack = button2.onPressed;
		lockon = buttonJstick.onPressed;
	}

}
